package com.wanaofu.model;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;


@Entity
@Table(name = "warehouse",uniqueConstraints ={@UniqueConstraint(columnNames={"warehouse_code","area_code","shelf_code", "floor_code"})})
public class Warehouse extends AbstractBaseEntity implements Serializable{
	private static final long serialVersionUID = -263825385845487690L;

	public Warehouse() {}
	
	public Warehouse(String ware,String area,String shelf,String floor) {
		this.warehouseCode = ware ;
		this.areaCode = area ;
		this.shelfCode = shelf ;
		this.floorCode = floor ;
	}
	
    @Column(name = "warehouse_code", nullable=false, length=50 )
    @NotNull(message="warehouseCode must not be null or empty.")
    @Size(min=1,max=10)
    private String warehouseCode;
	public String getWarehouseCode() {
		return warehouseCode;
	}
	public void setWarehouseCode(String warehouseCode) {
		this.warehouseCode = warehouseCode;
	}

    @Column(name = "area_code", nullable=false, length=50 )
    @NotNull(message="area_code must not be null or empty.")
    @Size(min=1,max=10)
    private String areaCode;
    
    @Column(name = "shelf_code", nullable=false, length=50 )
    @Size(min=1,max=10)
    @NotNull(message="shelfCode must not be null or empty.")
    private String shelfCode;
    
    @Column(name = "floor_code", nullable=false, length=50 )
    @NotNull(message="floorCode must not be null or empty.")
    @Size(min=1,max=10)
    private String floorCode;
    
    @Column(name = "max_weight", nullable=true )
    private BigDecimal maxWeight = new BigDecimal(Integer.MAX_VALUE);


    
	public String getAreaCode() {
		return areaCode;
	}
	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}
	public String getShelfCode() {
		return shelfCode;
	}
	public void setShelfCode(String shelfCode) {
		this.shelfCode = shelfCode;
	}
	public String getFloorCode() {
		return floorCode;
	}

	public void setFloorCode(String floorCode) {
		this.floorCode = floorCode;
	}

	public BigDecimal getMaxWeight() {
		return maxWeight;
	}

	public void setMaxWeight(BigDecimal maxWeight) {
		this.maxWeight = maxWeight;
	}

	@Override
	boolean businessEquals(Object p) {
		if (!(p instanceof Warehouse)) return false ;
		
		Warehouse cp = (Warehouse)p;
        
		return (this.warehouseCode + this.areaCode + this.shelfCode + this.floorCode)
				.equalsIgnoreCase(cp.getWarehouseCode()+cp.getAreaCode()+cp.getShelfCode()+cp.getFloorCode()) ;
	}
}
